BIN = main_page

BUILD_DIR = ./build

CC =  arm-openwrt-linux-gcc
CXX = arm-openwrt-linux-g++

LVGL_DIR = .
LVGL_DIR_NAME = lvgl

CFLAGS = -O3 -g0 -I$(LVGL_DIR)/$(LVGL_DIR_NAME) -I$(LVGL_DIR)
LDFLAGS = -lm -lpthread -lstdc++
CSRCS = 

CPPFLAGS =  $(CFLAGS)
CPPSRCS = ./main.cpp

VPATH = $(LVGL_DIR)

include $(LVGL_DIR)/custom/custom.mk
include $(LVGL_DIR)/application/application.mk
include $(LVGL_DIR)/$(LVGL_DIR_NAME)/lvgl.mk
include $(LVGL_DIR)/lv_drivers/lv_drivers.mk


AOBJS = $(addprefix $(BUILD_DIR)/, $(notdir $(ASRCS:.S=.o)))
COBJS = $(addprefix $(BUILD_DIR)/, $(notdir $(CSRCS:.c=.o)))
CPPOBJS = $(addprefix $(BUILD_DIR)/, $(notdir $(CPPSRCS:.cpp=.o)))

vpath %.c $(VPATH)

vpath %.cpp $(VPATH)

SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) $(CPPOBJS)

all: $(BUILD_DIR)/$(BIN)

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
	@echo "CC $<"
	@$(CC)  $(CFLAGS) -c $(INCLUDES) $< -o $@

$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
	@echo "CPP $<"
	@$(CXX)  $(CPPFLAGS) -c $(INCLUDES) $< -o $@

$(BUILD_DIR)/$(BIN): $(OBJS) Makefile
	@echo "ld $@"
	@$(CC)  $(OBJS) $(LDFLAGS) -o $@

$(BUILD_DIR):
	mkdir $@

.PHONY:clean
clean:
	rm -rf $(BUILD_DIR)
